home *** CD-ROM | disk | FTP | other *** search
- Path: lasernet.com!jonathan_wooldridge
- Newsgroups: comp.lang.c++
- Message-ID: <60107174041$71C7@lasernet.com>
- X-Gateway: Act-Up 4.6 07 Jan 96 17:40:41 LaserNet, Serving Fido style systems
- Date: Sun, 7 Jan 96 14:34:04 LOC
- Organization: 1BBS ■ Imperial Beach CA ■ 619∙429∙6521/6123 ■ (52:1000/153)
- From: Jonathan Wooldridge <jonathan_wooldridge@lasernet.com>
- In-Reply-To: Bret Bieghler
- Subject: Global Variables in GUI
-
- -=> Quoting Bret Bieghler to All <=-
- BB> Many people think that global variables are the children of Satan,
- BB> but here is a case where I'm not sure what to do.
-
- Hi Bret! Here's two ideas on this:
-
- 1). If several objects need access to the same data, the cleanest way might
- be to have them all be of the same class (or have them all be subclassed
- off the same class) then include a static data item, and manipulators.
-
- class CParent {
- protected:
- static int status
- int SetStatus(int s);
- }
- class foo : public CParent {
- /* whatever your current class is */
- }
- NOTE: be sure to declare static data items, just like you declare
- functions, in the code section, as they are effectively global in scope.
-
- 2). You might also try creating a global scope class object, CGlobal,
- that contains protected manipulator items. Then, any classes
- that will need to access the data/manipulator funcs could be declared
- as friends to the CGlobal object.
-
- class CGlobal {
- friend foo; // foo, and any other classes that will SetStatus
- protected:
- int SetStatus(int s);
- private:
- int status;
- };
-
- It's a thought. Happy Hunting!
-
- -SpyroGyra
- ---
- ■ TLX v4.00 ■ A drunken man's words are a sober man's thoughts.
-
- ---
-